package de.gameduell.framework.game.watch {
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flash.utils.getTimer;		

	/**
	 * @author cbra
	 */
	public class Time {
		private var startTime:Number;
		private var correctionTimer:Timer;
		private var passedTime:Number;
		
		public function Time() {
			correctionTimer = new Timer(100);
			correctionTimer.addEventListener(TimerEvent.TIMER, onTimeCorrection);
			passedTime = 0;
		}
		
		private function onTimeCorrection(event:TimerEvent):void{
			getCorrectedTime();
		}
		
		private function getCorrectedTime():Number{
			passedTime +=  Math.min(Math.max(getTimer()-startTime,0),200);
			startTime = getTimer();
			return passedTime;
		}
		
		public function start():void{		
			startTime = getTimer();
			correctionTimer.start();
		}
		
		public function stop():void{		
			correctionTimer.stop();
		}
		
		public function reset():void{
			passedTime = 0;
		}
		
		public function getPassedTime():Number{
			return getCorrectedTime();
		}
		
	}
}
